package com.sosolabs.com.site.client.presenter;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.sosolabs.com.site.client.AdUserServiceAsync;
import com.sosolabs.com.site.client.event.AdUserEvent;
import com.sosolabs.com.site.shared.AdUser;

public class CellListPresenter implements Presenter {
	public interface Display {
		HasClickHandlers getConfirmButton();
		HasClickHandlers getAddButton();
		HasClickHandlers getUpdateButton();
		void onAdd();
		void onUpdate();
		Widget asWidget();
	}
	
	private AdUserServiceAsync rpcService;
	private HandlerManager eventBus;
	private Display display;
	
	private AdUser adUser = new AdUser();
	
	public CellListPresenter(AdUserServiceAsync rpcService, HandlerManager eventBus, Display display) {
		this.rpcService = rpcService;
		this.eventBus = eventBus;
		this.display = display;
		bind();
	}
	
	public void go(final HasWidgets container) {
		container.clear();
		container.add(display.asWidget());
	}
	
	public void bind(){
		display.getConfirmButton().addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				eventBus.fireEvent(new AdUserEvent());
			}
		});
		display.getAddButton().addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				display.onAdd();
				//eventBus.fireEvent(new AdUserEvent());
			}
		});
		display.getUpdateButton().addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				display.onUpdate();
				//eventBus.fireEvent(new AdUserEvent());
			}
		});
	}
}
